package edu.nuist.javaProjct.view;

import edu.nuist.javaProjct.dao.StudentDatasourceDao;

import javax.swing.event.TableModelListener;
import javax.swing.table.TableModel;
import java.util.List;
import java.util.Map;

public class MyTableModel implements TableModel {

    StudentDatasourceDao studentBasicDao = new StudentDatasourceDao();
    List<Map<String, Object>> data;

    public MyTableModel() {
        data=studentBasicDao.listStudentMapData();
        System.out.println(data);
    }

    public void updateFullData(){
        data=studentBasicDao.listStudentMapData();
    }


    String column[]={"学号","姓名"};

    @Override
    public int getRowCount() {
        return data.size();
    }

    @Override
    public int getColumnCount() {
        return column.length;
    }

    @Override
    public String getColumnName(int columnIndex) {
        return column[columnIndex];
    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
        return Object.class;
    }

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return false;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {

        String[] column= {"stuID","name"};

        return data.get(rowIndex).get(column[columnIndex]);

    }

    @Override
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {

    }

    @Override
    public void addTableModelListener(TableModelListener l) {

    }

    @Override
    public void removeTableModelListener(TableModelListener l) {

    }
}
